﻿using System;

namespace DemoApp.Model
{
    internal sealed class ContactDetails
    {
        private String m_firstName;
        private String m_lastName;
        private String m_fullName;
        private String m_reversedFullName;

        /// <summary>
        /// Gets or sets the first name.
        /// </summary>
        /// <value>The first name.</value>
        public String FirstName
        {
            get
            {
                return m_firstName;
            }

            set
            {
                m_firstName = value;

                SetFullName();
                SetReversedFullName();
            }
        }

        /// <summary>
        /// Gets or sets the last name.
        /// </summary>
        /// <value>The last name.</value>
        public String LastName
        {
            get
            {
                return m_lastName;
            }

            set
            {
                m_lastName = value;
                
                SetFullName();
                SetReversedFullName();
            }
        }

        /// <summary>
        /// Gets or sets the full name.
        /// </summary>
        /// <value>The full name.</value>
        public String FullName
        {
            get
            {
                return m_fullName;
            }

            set
            {
                m_fullName = value;
            }
        }

        /// <summary>
        /// Gets or sets the reversed full name.
        /// </summary>
        /// <value>The reversed full name.</value>
        public String ReversedFullName
        {
            get
            {
                return m_reversedFullName;
            }

            set
            {
                m_reversedFullName = value;                
            }
        }

        /// <summary>
        /// Clears the full name.
        /// </summary>
        public void ClearFullName()
        {
            FirstName = String.Empty;
            LastName  = String.Empty;
        }

        /// <summary>
        /// Navigates to this contact's website.
        /// </summary>
        /// <param name="uriString">The URI string.</param>
        public void NavigateTo(String uriString)
        {
            System.Diagnostics.Process.Start(uriString);
        }

        private void SetFullName()
        {
            FullName = FirstName + " " + LastName;
        }

        private void SetReversedFullName()
        {
            ReversedFullName = Reverse(FullName);
        }

        private static String Reverse(String s)
        {
            Char[] charArray = s.ToCharArray();
            Array.Reverse(charArray);
            return new String(charArray);
        }
    }
}